-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize drag
and click
of Pointer
#2042
base: main
Are you sure you want to change the base?
Optimize drag
and click
of Pointer
#2042
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2042 +/- ##
==========================================
- Coverage 67.46% 66.07% -1.39%
==========================================
Files 471 462 -9
Lines 23809 23131 -678
Branches 3402 3413 +11
==========================================
- Hits 16062 15284 -778
- Misses 6556 6669 +113
+ Partials 1191 1178 -13 ☔ View full report in Codecov by Sentry. |
onPointerUp
and onPointerClick
drag
and click
of Pointer
packages/core/src/Script.ts
Outdated
* This function will be called when the pointer is pressed on the collider. | ||
* @param pointer | ||
*/ | ||
onPointerStartDrag(pointer: Pointer): void {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use onPointerBeginDrag
name, like onBeginRender
ane onEndRender
WalkthroughThe updates enhance pointer event handling in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- packages/core/src/Script.ts (1 hunks)
- packages/core/src/input/pointer/Pointer.ts (5 hunks)
- packages/core/src/input/pointer/PointerManager.ts (7 hunks)
- tests/src/core/input/InputManager.test.ts (5 hunks)
Additional comments not posted (27)
packages/core/src/input/pointer/Pointer.ts (13)
5-5
: Import of HitResultThe import statement for
HitResult
is necessary for the newhitResult
property. This change is appropriate and follows good practice for managing dependencies.
29-29
: Initialization of hitResultThe
hitResult
property is initialized correctly. This property is essential for storing the results of raycasting operations, which are crucial for pointer interactions in 3D environments.
33-33
: Initialization of _eventsMapThe
_eventsMap
property is initialized toPointerEventType.None
, which is a safe default ensuring that no pointer events are mistakenly flagged at initialization.
45-47
: Private entity tracking propertiesThe introduction of
_pressedEntity
,_enteredEntity
, and_draggedEntity
is crucial for managing the state of entities during different pointer interactions. This change enhances the tracking capabilities of thePointer
class.
52-54
: Getter methods for entity propertiesThe getter methods for
pressedEntity
,enteredEntity
, anddraggedEntity
are implemented correctly. These methods provide safe, read-only access to the internal state, which is a good practice in encapsulation.Also applies to: 59-61, 66-68
73-75
: Constructor implementationThe constructor correctly initializes the
id
property of thePointer
instance. This is essential for uniquely identifying each pointer, especially in multi-touch scenarios.
Line range hint
81-102
: Method to handle pointer exit and enter eventsThis method efficiently manages transitions between different entities during pointer interactions. The use of
_scripts
to trigger specific script actions is a robust design choice, facilitating complex interactions within the game or application environment.
109-122
: Method to handle pointer down and start drag eventsThis method consolidates the actions related to pointer down and drag start, reducing redundancy and enhancing the clarity of event handling. The simultaneous update of
_pressedEntity
and_draggedEntity
is a sensible approach, reflecting the start of a drag action.
127-140
: Method to handle pointer up and click eventsThe conditional check for
sameTarget
before firing theonPointerClick
event is a crucial detail that ensures the click event is only triggered when the pointer up event occurs on the same entity as the pointer down event. This prevents false positives in click detection.
147-148
: Method to fire pointer drag eventsThis method correctly triggers the
onPointerDrag
event for the_draggedEntity
. It's well-implemented to support continuous drag interactions, crucial for user interfaces and interactive applications.
162-174
: Method to handle pointer end drag eventsThe separation of concerns is well maintained here, with clear handling of the end drag event. The conditional check for
receivingEntity
to triggeronPointerDrop
is a thoughtful addition, allowing for more complex drag-and-drop interactions.
181-183
: Dispose method implementationThe
_dispose
method correctly nullifies all relevant properties, ensuring that the pointer instance is cleaned up properly. This is crucial for managing memory and preventing leaks in applications with complex interactions.
187-194
: PointerEventType enumThe introduction of the
PointerEventType
enum is a significant enhancement for managing different types of pointer events. This structured approach facilitates clearer and more maintainable event handling code.packages/core/src/Script.ts (2)
166-167
: Implementation of onPointerEndDragThe method is implemented correctly, providing a clear and specific handler for the end of a drag event. This addition enhances the script's capabilities to react to complex pointer interactions.
172-173
: Implementation of onPointerDropThe
onPointerDrop
method is a new addition that handles the scenario where a pointer is lifted from a collider during a drag operation. This method is crucial for implementing drag-and-drop functionality.packages/core/src/input/pointer/PointerManager.ts (7)
12-12
: Import of Pointer and PointerEventTypeThe import of
Pointer
andPointerEventType
is necessary for the updated functionality in this file. This change is appropriate and integrates well with the rest of the codebase.
76-76
: Pointer disposal in the update loopThe addition of the
_dispose
call within the cleanup loop is a critical improvement. It ensures that pointer instances are properly cleaned up, preventing memory leaks and ensuring that the system's state is correctly maintained.
116-116
: Reset of _eventsMap in the update loopResetting
_eventsMap
toPointerEventType.None
at the start of each update cycle is a good practice. It ensures that event states do not persist incorrectly across frames.
130-135
: Pointer raycasting method callThe modification to include
hitResult
in the_pointerRayCast
method call is a necessary update to support the new functionality in thePointer
class. This change allows for more accurate and detailed handling of pointer interactions.
139-142
: Handling of pointer move eventsThe handling of pointer move events with the new
_firePointerDrag
method call is an appropriate update. It ensures that drag events are processed correctly, enhancing the responsiveness and accuracy of the interface.
148-153
: Enhanced event handling for pointer down and upThe updates to handle pointer down and up events more comprehensively, including the initiation and termination of drag operations, are well-implemented. These changes make the event handling more robust and intuitive.
159-159
: Handling of pointer leave and cancel eventsThe addition of
_firePointerEndDrag
in the context of pointer leave and cancel events is a crucial update. It ensures that drag operations are correctly terminated even when unexpected events like pointer leave occur.tests/src/core/input/InputManager.test.ts (5)
84-86
: Setup of camera and box entities in testsThe adjustments to the camera and box entities, including their positions and sizes, are appropriate for testing the new pointer functionality. These changes ensure that the tests are relevant and effective for the new features.
Also applies to: 89-89, 92-92
108-110
: Implementation of pointer event handlers in TestScriptThe new methods
onPointerUp
,onPointerStartDrag
,onPointerEndDrag
, andonPointerDrop
in theTestScript
class are correctly implemented. These methods enhance the test coverage for the new pointer event functionality.Also applies to: 116-118, 124-126, 128-129
138-138
: Spying on methods and dispatching events in testsThe use of
chai.spy
on new methods and the dispatching of pointer events to test these methods are correctly done. These tests effectively verify the functionality of the new event handlers.Also applies to: 142-154, 162-162
182-211
: New tests for onPointerClickThe new tests for the
onPointerClick
event handler are comprehensive and well-structured. They effectively test various scenarios to ensure that the handler behaves as expected under different conditions.
235-261
: Hit result testsThe tests for hit results are crucial for verifying the accuracy of pointer interactions with 3D objects. These tests are well-implemented, covering various scenarios to ensure the functionality is robust and reliable.
packages/core/src/Script.ts
Outdated
* This function will be called when the pointer is pressed on the collider. | ||
* @param pointer | ||
*/ | ||
onPointerStartDrag(pointer: Pointer): void {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method naming consistency
The previous comment suggests renaming onPointerStartDrag
to onPointerBeginDrag
for consistency with other method names like onBeginRender
. This is a valid suggestion to maintain a consistent naming convention throughout the API.
- onPointerStartDrag(pointer: Pointer): void {}
+ onPointerBeginDrag(pointer: Pointer): void {}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
onPointerStartDrag(pointer: Pointer): void {} | |
onPointerBeginDrag(pointer: Pointer): void {} |
* This function will be called when the pointer is lifted on the collider. | ||
* @param pointer - The pointer that triggered | ||
*/ | ||
onPointerDrop(pointer: Pointer): void {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the comments is right and clearly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- packages/core/src/Script.ts (1 hunks)
- packages/core/src/input/pointer/Pointer.ts (5 hunks)
- tests/src/core/input/InputManager.test.ts (5 hunks)
Files skipped from review as they are similar to previous changes (2)
- packages/core/src/Script.ts
- tests/src/core/input/InputManager.test.ts
Additional comments not posted (11)
packages/core/src/input/pointer/Pointer.ts (11)
28-29
: LGTM! Addition ofhitResult
property.The
hitResult
property captures raycasting results for the current frame, enhancing pointer interaction tracking.
45-47
: LGTM! Renaming and addition of properties.The renaming of
_currentPressedEntity
to_pressedEntity
and_currentEnteredEntity
to_enteredEntity
improves readability. The addition of_draggedEntity
is logical for tracking drag events.
52-68
: LGTM! Addition of getter methods.The addition of getter methods for
pressedEntity
,enteredEntity
, anddraggedEntity
provides convenient access to these properties.
73-75
: LGTM! Addition of constructor.The constructor initializes the
id
property, which is necessary for thePointer
class.
Line range hint
81-102
:
LGTM! Update to_firePointerExitAndEnter
.The update to use
_enteredEntity
improves consistency with the renamed property.
109-122
: LGTM! Renaming and update to_firePointerDownAndStartDrag
.The renaming and update to initialize
_draggedEntity
are logical for handling drag events.
127-140
: LGTM! Addition of_firePointerUpAndClick
.The addition of
_firePointerUpAndClick
is logical for managing pointer up events and clicks.
Line range hint
147-152
:
LGTM! Update to_firePointerDrag
.The update to use
_draggedEntity
is logical for handling drag events.
162-174
: LGTM! Addition of_firePointerEndDrag
.The addition of
_firePointerEndDrag
is logical for handling the end of dragging.
181-183
: LGTM! Addition of_dispose
.The addition of
_dispose
is logical for resetting the state of the pointer.
187-194
: LGTM! Addition ofPointerEventType
enum.The addition of
PointerEventType
enum is logical for categorizing pointer events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/core/src/Script.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/core/src/Script.ts
Script
new callback about drag and dropPointer
new APISummary by CodeRabbit
New Features
onPointerBeginDrag
,onPointerEndDrag
, andonPointerDrop
).Bug Fixes
Tests
Refactor